import router from "./index"
import {
	getToken,
	removeToken,
	removeUserName,
	removeUserImg
} from "@/utils/cookie.js"

const whiteRouter = ["/login"];

router.beforeEach((to, from, next) => {
	// console.log(to);
	if (getToken()) {
		//路由动态添加，分配菜单，每个角色分配不同的菜单
		//token存在
		if (to.path === "/login") {
			removeToken();
			removeUserImg();
			removeUserName();
			next();
		}else{
			next();
		}
		
	} else {
		//token不存在
		if (whiteRouter.indexOf(to.path) != -1) {
			next()
		} else {
			next('/login')
		}
	}
})
